/*************************************************
 * HISTORY:                                      *
 *	06/22/2020 pyx : Created.                    *
 *	03/04/2021 pyx : Edited.                     *
=================================================*/


#ifndef DATRANSFORMER_CONNECTOR_H
#define DATRANSFORMER_CONNECTOR_H

#include <iostream>
#include <sstream>
#include <memory>
#include <string>
#include <stdexcept>

#include "DAType.h"

#include <mysql_driver.h>
#include <mysql_connection.h>
#include <cppconn/driver.h>
#include <cppconn/statement.h>
#include <cppconn/prepared_statement.h>
#include <cppconn/metadata.h>
#include <cppconn/exception.h>

#define DBHOST "tcp://127.0.0.1:3306"
#define USER "root"
#define PASSWORD "123456"

class Connector
{

public:
    Connector();
    ~Connector();

    void insertSymbol(unsigned sid,std::string signature,int symboltype,std::string name);
    void insertDef(unsigned refid,unsigned sid, unsigned fid,int reftype,std::string location);
    void insertDec(unsigned refid,unsigned sid, unsigned fid,int reftype,std::string location);
    void insertRef(unsigned refid,unsigned sid, unsigned fid,int reftype,std::string location);
    void insertFile(std::string filepath, unsigned fid);
    void insertSymbolDep(unsigned sdepid, unsigned ssid, unsigned esid, int symboldeptype);

    void commit();

private:
    sql::Driver *driver;
    sql::Connection *con;

    sql::PreparedStatement *check_symbol_prep_stmt;
    sql::PreparedStatement *insert_symbol_prep_stmt;

    sql::PreparedStatement *check_def_prep_stmt;
    sql::PreparedStatement *insert_def_prep_stmt;

    sql::PreparedStatement *check_dec_prep_stmt;
    sql::PreparedStatement *insert_dec_prep_stmt;

    sql::PreparedStatement *check_ref_prep_stmt;
    sql::PreparedStatement *insert_ref_prep_stmt;

    sql::PreparedStatement *check_file_prep_stmt;
    sql::PreparedStatement *insert_file_prep_stmt;

    sql::PreparedStatement *check_dup_sym_dep_prep_stmt;
    sql::PreparedStatement *insert_sym_dep_prep_stmt;
};

#endif //DATRANSFORMER_CONNECTOR_H
